package theOrbalEra.common.network;

import theOrbalEra.common.TheOrbalEra;
import theOrbalEra.common.util.idList.PacketId;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class PacketHandler implements IPacketHandler {
	@Override
	public void onPacketData(INetworkManager manager,
			Packet250CustomPayload packet, Player player) {
		ByteArrayDataInput dat = ByteStreams.newDataInput(packet.data);
		int id = dat.readInt();
		// System.out.println("packet");
		Object[] extradata = { (EntityPlayer) player };
		switch (FMLCommonHandler.instance().getEffectiveSide()) {
		case SERVER: {
			switch (id) {
			case PacketId.BANK_ACTION:
				PacketGetQuartz.instance.readServer(id, dat,
						extradata);
				break;
			case PacketId.OPEN_CAO:
				PacketSetOpen.instance.readServer(id, dat,
						extradata);
				break;
			case PacketId.DE_BAG:
				PacketDeBag.instance.readServer(id, dat,
						extradata);
				break;
			case PacketId.DE_ELE:
				PacketDeEle.instance.readServer(id, dat,
						extradata);
				break;
			case PacketId.PLAYER_DATA:
				TheOrbalEra.instance.playerData.readServer(id, dat,
						extradata);
				break;
			case PacketId.ENTITY_SPAWN:
				PacketSpawnEntity.instance.readServer(id, dat,
						extradata);
				break;
			case PacketId.FX_SPAWN:
				PacketSpawnFX.instance.readClient(id, dat, extradata);
				break;
			
			
			}
			break;
		}
		case CLIENT: {
			switch (id) {
			case PacketId.PLAYER_DATA:
				TheOrbalEra.instance.playerData.readClient(id, dat,
					extradata);
				break;
			case PacketId.PLAYER_ACTION:
				PacketPlayerHandler.instance.readClient(id, dat, extradata);
				break;
			
			}
			break;
		
			
		}
		default:
			break;
		}
	}

}